package com.lipl.base.javaee.netty.nio;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Auther: 15541
 * @Date: 2020/10/30 20:09
 * @Description:
 */
public class NIOFileChannel01 {
    public static void main(String[] args) throws IOException {

        String str = "hello，李鹏龙";

        FileOutputStream fileOutputStream = new FileOutputStream("d:\\file01.txt");

        FileChannel fileChannel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

        byteBuffer.put(str.getBytes());

        byteBuffer.flip();

        //将byteBuffer 数据写入到fileChannel
        fileChannel.write(byteBuffer);
        fileOutputStream.close();

    }
}

